package __test;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2023/3/22 10:12
 */
public class Main1 {
    public static void main(String[] args) {
//        String s = "abcabcbb";
//        String s = "bbbb";
//        String s = "abba";
//        String s = "dvdf";
        String s = "pwwkew";
        System.out.println(lengthOfLongestSubstring(s));
    }
    public static int lengthOfLongestSubstring(String s) {
        int lp = 0;
        int rp = 0;
        int max = 0;
        Set<Character> set = new HashSet<>(s.length());
        char[] chars = s.toCharArray();
        while (rp < chars.length){
            if(set.add(chars[rp])){
                rp++;
            }else{
                max = Math.max(max,rp-lp);
                lp++;
                rp = lp;
                set.clear();
            }
        }
        return Math.max(max,rp-lp);
    }
    /*


     int lp = 0;
        int rp = 0;
        int max = 0;
        Set<Character> set = new HashSet<>(s.length());
        char[] chars = s.toCharArray();
        while (rp < chars.length){
            if(set.add(chars[rp])){
                rp++;
            }else{
                max = Math.max(max,rp-lp);
                lp++;
                rp = lp;
                set.remove(chars[rp]);
            }
        }
        return Math.max(max,rp-lp);







     */
}

